/**
 * 
 */
package cn.sundat.web.filter;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;

import cn.sundat.model.User;

/**
 * @author XIN
 *
 */
// --------------MethodFilterInterceptor方式实现------------
public class LoginFilter extends MethodFilterInterceptor {

	@Override
	protected String doIntercept(ActionInvocation arg0) throws Exception {
		// TODO Auto-generated method stub
		User user = (User) ServletActionContext.getRequest().getSession().getAttribute("userInfo");
		if (user == null) {
			return Action.LOGIN;
		}
		return arg0.invoke();
	}
}
// --------------AbstractInterceptor方式实现------------
// public class LoginFilter extends AbstractInterceptor {
//
// @Override
// public void destroy() {
// // TODO Auto-generated method stub
// System.out.println("---登录过滤结束---");
// }
//
// @Override
// public void init() {
// // TODO Auto-generated method stub
// System.out.println("---登录过滤开始---");
// }
//
// @Override
// public String intercept(ActionInvocation arg0) throws Exception {
// // TODO Auto-generated method stub
// if (!"user_loginCheck".equals(arg0.getProxy().getMethod())) {
// System.out.println("有人登录？");
// Object object = arg0.getInvocationContext().getSession().get("userInfo");
// if (object==null) {
// System.out.println("没人登录呢");
// }else {
// System.out.println("用户名："+((User)object).getUname());
// }
// }
// return arg0.invoke();
// }
//
// }
